package com.qf.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qf.base.BaseServlet;
import com.qf.model.Pagebean;
import com.qf.model.Product;

/**
 * Servlet implementation class ProductServlet
 */
public class ProductServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
  
	/**
	 * 分页查询
	* @author: 千锋学员邓鹏
	* @createTime: 2017年7月5日 下午5:24:44
	* @history:
	* @param request
	* @param response
	* @throws ServletException
	* @throws IOException void
	 */
	protected void showProductByPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		int currentPage=1;
		int pagesize=6;
		String currentPage_ = request.getParameter("currentPage");
		if(currentPage_!=null){
			currentPage=Integer.parseInt(currentPage_);
		}
		
		String cid = request.getParameter("cid");
		Pagebean pd1=productServiceImpl.findother(currentPage,pagesize,Integer.parseInt(cid));
//		System.out.println(pd1);
		request.setAttribute("cid", cid);
		request.setAttribute("pb", pd1);
		request.getRequestDispatcher("product_list.jsp").forward(request, response);
		
	}
	/**
	 * 搜索分页查询
	* @author: 千锋学员邓鹏
	* @createTime: 2017年7月5日 下午5:24:55
	* @history:
	* @param request
	* @param response
	* @throws ServletException
	* @throws IOException void
	 */
	protected void findProductBySearch(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		   response.setCharacterEncoding("text/html;charset=utf-8");
		   String name = request.getParameter("name");
		   String currentPage_ = request.getParameter("currentPage");
		   int currentPage=1;
		   if(currentPage_!=null){
			   currentPage=Integer.parseInt(currentPage_);
		   }
		   int pagesize=6;
		   Pagebean p=productServiceImpl.findother(currentPage, pagesize, name);
		   request.setAttribute("pb", p);
		   request.setAttribute("name", name);
		   request.getRequestDispatcher("product_list1.jsp").forward(request, response);
		}
	
	protected void info(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	   response.setCharacterEncoding("text/html;charset=utf-8");
	   String pid = request.getParameter("pid");
	   Product p=productServiceImpl.findByPid(pid);
	   request.setAttribute("pd", p);
		request.getRequestDispatcher("product_info.jsp").forward(request, response);
	}

	

}
